package com.yss.reportworld.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.alibaba.fastjson.JSONArray;
import com.yss.common.core.utils.easyexecl.EasyExeclUtil;
import com.yss.reportworld.domain.DatabaseDispose;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.yss.common.logger.annotation.Log;
import com.yss.common.logger.enums.BusinessType;
import com.yss.common.security.annotation.RequiresPermissions;
import com.yss.reportworld.service.IDatabaseDisposeService;
import com.yss.common.core.web.controller.BaseController;
import com.yss.common.core.web.domain.AjaxResult;
import com.yss.common.core.web.page.TableDataInfo;

/**
 * 基础数据配置信息Controller
 *
 * @author yss
 * @date 2023-04-02
 */
@RestController
@RequestMapping("/dispose")
public class DatabaseDisposeController extends BaseController {
    @Autowired
    private IDatabaseDisposeService databaseDisposeService;

    /**
     * 查询基础数据配置信息列表
     */
    @RequiresPermissions("reportworld:dispose:list")
    @GetMapping("/list")
    public TableDataInfo list(DatabaseDispose databaseDispose) {
        startPage();
        List<DatabaseDispose> list = databaseDisposeService.selectDatabaseDisposeList(databaseDispose);
        return getDataTable(list);
    }

    /**
     * 导出基础数据配置信息列表
     */
    @RequiresPermissions("reportworld:dispose:export")
    @Log(title = "基础数据配置信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DatabaseDispose databaseDispose) {
        List<DatabaseDispose> list = databaseDisposeService.selectDatabaseDisposeList(databaseDispose);
        EasyExeclUtil.export(response, list, DatabaseDispose.class);
    }

    /**
     * 获取基础数据配置信息详细信息
     */
    @RequiresPermissions("reportworld:dispose:query")
    @PostMapping(value = "/getDispose")
    public AjaxResult getDispose(@RequestBody DatabaseDispose databaseDispose) {
        return success(databaseDisposeService.selectDatabaseDisposeOne(databaseDispose));
    }

    /**
     * 新增基础数据配置信息
     */
    @RequiresPermissions("reportworld:dispose:add")
    @Log(title = "基础数据配置信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody @Validated DatabaseDispose databaseDispose) {
        databaseDisposeService.addDatabaseDispose(databaseDispose);
        return success();
    }

    /**
     * 修改基础数据配置信息
     */
    @RequiresPermissions("reportworld:dispose:edit")
    @Log(title = "基础数据配置信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody @Validated DatabaseDispose databaseDispose) {
        databaseDisposeService.editDatabaseDispose(databaseDispose);
        return success();
    }

    /**
     * 删除基础数据配置信息
     */
    @RequiresPermissions("reportworld:dispose:remove")
    @Log(title = "基础数据配置信息", businessType = BusinessType.DELETE)
    @PostMapping("/remove")
    public AjaxResult remove(@RequestBody DatabaseDispose databaseDispose) {
        databaseDisposeService.delDatabaseDispose(databaseDispose);
        return success();
    }


    /**
     * 初始化的时候 不初始化策略信息
     */
    @RequiresPermissions("reportworld:dispose:init")
    @Log(title = "基础数据配置信息", businessType = BusinessType.OTHER)
    @PostMapping("/initDispose")
    public AjaxResult initDispose(@RequestBody DatabaseDispose databaseDispose) {
        databaseDisposeService.initDispose(databaseDispose, false);
        return success();
    }


    /**
     * 保存表顺序信息
     */
    @RequiresPermissions("reportworld:dispose:orderNum")
    @Log(title = "基础数据配置信息", businessType = BusinessType.UPDATE)
    @PostMapping("/handleUpdateOrderNum")
    public AjaxResult handleUpdateOrderNum(@RequestBody String josn) {
        List<DatabaseDispose> list = JSONArray.parseArray(josn, DatabaseDispose.class);
        databaseDisposeService.handleUpdateOrderNum(list);
        return success();
    }
}
